<?php

declare (strict_types=1);

namespace app\store\controller\agent;


use app\store\controller\Controller;
use think\App;
use think\response\Json;
use app\store\service\agent\Bind as BindService;

/**
 * 绑定操作
 * Class Setting
 * @package app\store\controller
 */
class Bind extends Controller
{
    private $bindService;
    public function __construct(App $app,BindService $bindService)
    {
        parent::__construct($app);
        $this->bindService = $bindService;
    }

    /**
     * 绑定操作
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function done():Json
    {
        $params = $this->request->post();
        $this->validate(
            $params,
            [
                'player_user_id' => 'require|integer',
                'promoter_user_id' => 'require|integer'
            ]
        );
        $res = $this->bindService->getDone($params);
        if(!$res){
            return $this->renderError('绑定异常');
        }
        return $this->renderSuccess([],'绑定成功');
    }

    /**
     * 解绑操作
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function cancel():Json
    {
        $params = $this->request->post();
        $this->validate(
            $params,
            [
                'player_user_id' => 'require|integer',
            ]
        );
        $res = $this->bindService->cancel($params);
        if(!$res){
            return $this->renderError('解绑异常');
        }
        return $this->renderSuccess([],'解绑成功');
    }

    /**日志
     * @return Json
     */
    public function log():Json
    {
        $params = $this->request->get();
        $this->validate(
            $params,
            [
                'page' => 'integer',
                'limit' => 'integer',
                'type' => 'integer' //1绑定 2解绑
            ]
        );
        $list = $this->bindService->getBindLogs($params);
        return $this->renderSuccess(compact('list'));
    }

}
